﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var isJump = false;
    var currRowId = 0;
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
        initBindSelect("#form1");
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/MainData/Container/GetSupplierListJson",
            height: $(window).height() - 118,
            colModel: [
                { label: '容器编号', name: 'FContainerNO', width: 90, align: 'center', sortable: false, frozen: true },
                { label: '容器名称', name: 'FContainerName', width: 90, align: 'center', sortable: false, frozen: true },
                { label: '制造单位编号', name: 'FProCompanyNO', width: 120, align: 'left', sortable: false },
                { label: '制造单位名称', name: 'FProCompanyName', width: 200, align: 'left', sortable: false },
                { label: '叠加层次', name: 'FLayerCount', width: 80, align: 'right', sortable: false },
                { label: '外形尺寸(mm)', name: 'OutlineSize', width: 120, align: 'left', sortable: false },
                { label: '内形尺寸(mm)', name: 'InnerSize', width: 120, align: 'left', sortable: false },
                { label: '容器重量(kg)', name: 'FContainerWeight', width: 100, align: 'right', sortable: false },
                { label: '制造日期', name: 'ProductDate', width: 90, align: 'center', sortable: false },
                { label: '容器分类', name: 'FContainerTypeNO', width: 80, align: 'center', sortable: false, hidden: true },
                { label: '容器分类', name: 'FContainerTypeName', width: 100, align: 'center', sortable: false },
                { label: '数量(套)', name: 'FContainerSum', width: 60, align: 'right', sortable: false },
                { label: '备注说明', name: 'Fdesc', width: 180, align: 'left', sortable: false },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'center', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 80, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 80, align: 'center', sortable: false },
                { label: '更改人员', name: 'FUpdateBy', width: 80, align: 'center', sortable: false },
                { label: '更改日期', name: 'FUpdateDate', width: 80, align: 'center', sortable: false },
                { label: '更改时间', name: 'FUpdateTime', width: 80, align: 'center', sortable: false },
                { label: '容器ID', name: 'FContainerID', width: 80, align: 'center', sortable: false, hidden: true },
            ],
            pager: "#gridPager",
            sortname: 'FContainerNO asc,FProCompanyNO asc',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {
            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    $gridList.jqGrid('setSelection', currRowId);
                    var $grid = $('#gview_gridList .ui-jqgrid-bdiv');
                    if (isJump) {
                        $grid.setScrollTop(length, currRowId);
                        isJump = false;
                    } else {
                        var top = $grid.scrollTop();
                        $grid.scrollTop(top + 1);
                    }
                }
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                $('#btn_remove').removeClass("disabled");
                $('#btn_edit').removeClass("disabled");
            },
            onPaging: function (page_btn) {
                currRowId = 1;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            reloadGrid();
        });
    }
    function reloadGrid(currNumber) {
        currNumber = currNumber || '';
        var currPage = 1;
        if (currNumber != "") {
            //var data = $("#form1").formSerialize();
            var data = {};
            var page = $('#gridList').getGridParam('page'); // current page
            var rows = $('#gridList').getGridParam('rowNum'); // rows
            var sidx = $('#gridList').getGridParam('sortname'); // sidx
            var sord = $('#gridList').getGridParam('sortorder'); // sord
            data["sidx"] = sidx;
            data["sord"] = sord;
            data["rows"] = rows;
            data["currNumber"] = currNumber;
            $.ajaxSetup({ async: false });
            $.getJSON("/MainData/Container/GetSupplierSortJson", data, function (result) {
                currPage = result.currPage;
                currRowId = result.currIndex;
            });
            $.ajaxSetup({ async: true });
            emptyDataById("#form1");
            $("#gridList").jqGrid('setGridParam', {
                page: currPage,
            }).trigger('reloadGrid');
        } else {
            $("#gridList").jqGrid('setGridParam', {
                postData: $("#form1").formSerialize(),
            }).trigger('reloadGrid');
        }

    }
    function btn_add() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        var number = rowData.FContainerID == undefined ? "" : rowData.FContainerID;
        $.detailOpenTop({
            id: "Detail",
            title: "添加供应商容器信息",
            width: 950,
            height: $(window).height() - 2,
            url: "/MainData/Container/SupplierListInput?status=I&number=" + number
        });
    }
    function btn_edit() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        var number = rowData.FContainerID == undefined ? "" : rowData.FContainerID;
        $.detailOpenTop({
            id: "Detail",
            title: "修改供应商容器信息",
            width: 950,
            height: $(window).height() - 2,
            url: "/MainData/Container/SupplierListInput?status=U&number=" + number
        });
    }
    function btn_remove() {
        var rowData = $("#gridList").jqGrid('getRowData', currRowId);
        $.modalConfirm("注：您确定要【删除】该条数据吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/MainData/Container/SubmitSupplierListForm?status=D",
                    param: { keyValue: rowData.FContainerID },
                    success: function () {
                        reloadGrid();
                    }
                })
            }
        });
    }
    function btn_export() {
        var url = "/Common/ExcelExport?" + encodeURI(init_sql());
        location.href = url;
    }
    function init_sql() {
        var tablename = "V_ZSJ_23_GH_SuContainer";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#FContainer').val() != '') {
            condition += " AND (FContainerNO LIKE '%" + $('#FContainer').val() + "%' OR FContainerName LIKE '%" + $('#FContainer').val() + "%')";
        }
        if ($('#FProCompanyNO').val() != '') {
            condition += " AND FProCompanyNO='" + $('#FProCompanyNO').val() + "'";
        }
        if ($('#FContainerTypeNO').val() != '') {
            condition += " AND FContainerTypeNO='" + $('#FContainerTypeNO').val() + "'";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY FContainerNO ASC,FProCompanyNO ASC";
        return "sql=" + sql;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <form id="form1">
        <div style="padding: 12px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc; " class="line-table input-width-140">
            <div class="btn-group" style="margin-top:-9px;">
                容器编号/名称<br /><input id="FContainer" name="FContainer" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group input-width-185" style="margin-top:-9px;">
                所属单位<br />
                <select id="FProCompanyNO" name="FProCompanyNO" class="form-control">
                    <option value="">&nbsp;</option>
                    @foreach (var item in ViewBag.proCompany)
                    {
                        <option value="@item.UnitNO">@item.UnitNO @item.UnitShortName</option>
                    }
                </select>
                &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                容器分类<br />
                <select id="FContainerTypeNO" name="FContainerTypeNO" class="form-control">
                    <option value="">&nbsp;</option>
                    @foreach (var item in ViewBag.containerType)
                    {
                        <option value="@item.FTypeNO">@item.FTypeNO @item.FTypeName</option>
                    }
                </select>
                &nbsp;
            </div>
            <div class="btn-group" style="">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div class="btn-group" style="float:right;">
                <a id="" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_add" class="btn btn-primary center-block" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 新增</a>
                <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                <a id="btn_edit" class="btn btn-primary center-block disabled" onclick="btn_edit()"><span class="glyphicon glyphicon-edit"></span> 修改</a>
                <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
    </form>
    <div style="">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>

